home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / WindowMaker / src / wmnotify.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-29  |  3.4 KB  |  140 lines

  1. /*
  2.  *  WindowMaker external notification support
  3.  * 
  4.  *  Copyright (c) 1998 Peter Bentley (pete@sorted.org)
  5.  * 
  6.  *  This program is free software; you can redistribute it and/or modify
  7.  *  it under the terms of the GNU General Public License as published by
  8.  *  the Free Software Foundation; either version 2 of the License, or
  9.  *  (at your option) any later version.
  10.  *
  11.  *  This program is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *  GNU General Public License for more details.
  15.  *
  16.  *  You should have received a copy of the GNU General Public License
  17.  *  along with this program; if not, write to the Free Software
  18.  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 
  19.  *  USA.
  20.  */
  21.  
  22. #include "wconfig.h"
  23.  
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <X11/X.h>
  27. #include <X11/Xlib.h>
  28. #include <X11/Xutil.h>
  29. #include <X11/Xproto.h>
  30.  
  31. #include "WindowMaker.h"
  32. #include "wcore.h"
  33. #include "framewin.h"
  34. #include "window.h"
  35. #include "properties.h"
  36. #include "wmnotify.h"
  37.  
  38. #ifdef WMNOTIFY
  39. #define DEBUG
  40. extern Atom _XA_WINDOWMAKER_NOTIFY;
  41.  
  42. static LinkedList *wNotifyWindows=NULL;
  43.  
  44. typedef struct WNotifyClient
  45. {
  46.     Window    not_win;        /* Id of window to send notify events to */
  47.     int        not_mask;    /* Mask of desired notifications     */
  48. } WNotifyClient;
  49.  
  50.  
  51. void wNotify( int id, int a1, int a2 )
  52. {
  53. }
  54.  
  55.  
  56. void wNotifyWin( int id, WWindow *wwin )
  57. {
  58.     XEvent        event;
  59.     LinkedList        *list;
  60.     WNotifyClient          *clnt;
  61.     int            count = 0, mask = WMN_ID_TO_MASK( id );
  62.  
  63.     event.xclient.type = ClientMessage;
  64.     event.xclient.message_type = _XA_WINDOWMAKER_NOTIFY;
  65.     event.xclient.format = 32;
  66.     event.xclient.display = dpy;
  67.     event.xclient.data.l[0] = id;
  68.     if( wwin )
  69.     event.xclient.data.l[1] = wwin->client_win; /* XXX */
  70.     else
  71.     event.xclient.data.l[1] = 0;
  72.     event.xclient.data.l[2] = 0;
  73.     event.xclient.data.l[3] = 0;
  74.  
  75.     for( list = wNotifyWindows; list; list = list->tail )
  76.     {
  77.     clnt = list->head;
  78.     if( clnt->not_mask & mask )
  79.     {
  80. #ifdef DEBUG
  81.         printf( "Send event %d to 0x%x\n", id, (int) clnt->not_win );
  82. #endif
  83.         event.xclient.window = clnt->not_win;
  84.         XSendEvent(dpy, clnt->not_win, False, NoEventMask, &event);
  85.         count++;
  86.     }
  87.     }
  88.     if( count )
  89.     XFlush(dpy);
  90. }
  91.  
  92.  
  93. int wNotifySet(Window window)
  94. {
  95.     int            mask;
  96.     WNotifyClient    *clnt;
  97.  
  98.     if( PropGetNotifyMask( window, &mask )) {
  99.     wNotifyClear( window );    /* Remove any current mask */
  100. #ifdef DEBUG
  101.     printf( "Setting notify mask for window 0x%x to 0x%02x\n",
  102.         (int) window, mask );
  103. #endif
  104.     clnt = wmalloc( sizeof( WNotifyClient ));
  105.     if( clnt )
  106.     {
  107.         clnt->not_win = window;
  108.         clnt->not_mask = mask;
  109.         wNotifyWindows = list_cons( clnt, wNotifyWindows );
  110.         return True;
  111.     }
  112.     }
  113.     return False;
  114. }
  115.  
  116. int wNotifyClear(Window window)
  117. {
  118.     LinkedList        *list;
  119.     WNotifyClient          *clnt;
  120.  
  121.     for( list = wNotifyWindows; list; list = list->tail )
  122.     {
  123.     clnt = list->head;
  124.     if( clnt->not_win == window )
  125.     {
  126. #ifdef DEBUG
  127.         printf( "Clearing notify mask for window 0x%x (was 0x%02x)\n",
  128.             (int) clnt->not_win, clnt->not_mask );
  129. #endif
  130.         wNotifyWindows = list_remove_elem( wNotifyWindows, clnt );
  131.         free( clnt );
  132.         return True;
  133.     }
  134.     }
  135.     return False;
  136. }
  137.  
  138.  
  139. #endif /* WMNOTIFY */
  140.